/**
 * Created with JetBrains WebStorm.
 * User: 可乐加糖
 * Date: 13-7-22
 * Time: 下午12:47
 * To change this template use File | Settings | File Templates.
 */

var express = require("express");
//启动服务器并监听
var app = express();
app.listen(8000);

var tweets = [];

//基础API GET方法
app.get("/",function(req,res){
    res.send("Welcome to Node Twitter");
});
//基础API POST方法
app.post("/send",express.bodyParser(),function(req,res){
    if(req.body && req.body.tweet){
        tweets.push(req.body.tweet);
        res.send({status:"ok",message:"Tweet received"});
    }else{
        //没有TWEET
        res.send({status:"nok",message:"No tweet received"});
    }
});

app.get("/tweets",function(req,res){
    res.send(tweets)
})

console.log("Server is running...");